const { Transform } = require('stream');
const utils = require('../../utils');

module.exports = function ({ inFormat } = {}) {
  const stream = new Transform({ objectMode: true });
  inFormat = utils.parseFunction(inFormat);
  let i = 0;
  stream._transform = async function (chunk, encoding, callback) {
    const params = inFormat ? await inFormat(chunk, { _, moment, utils }) : chunk;
    console.log(`${i++}:`, params);
    stream.push(chunk);
    callback();
  };
  return stream;
};